<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>新建标准任务</title>
    <script type="text/javascript">
      var templateId = <%=params[:templateId]%>
      Ext.onReady(function(){
        var teamDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/team/getAllTeams?for_cbb=true'}),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
            totalProperty: 'total',
            root:'team'
          }, [
            {name:'name'},
            {name:'id'}
          ])
        });
        var team = new Ext.form.ComboBox({
          store: teamDS,
          displayField:'name',
          hiddenName:'teamId',
          valueField:'id',
          typeAhead: true,
          allowBlank:false,
          blankText:'请选择组队',
          minChars:0,
          anchor: '90%',
          mode: 'remote',
          fieldLabel:'组队',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择组队.....',
          selectOnFocus:true
        });

        var workDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/work/getAllWorks'}),
          reader:new Ext.data.JsonReader({
            totalProperty: 'total',
            root:'work'
          }, [
            {name:'name'},
            {name:'id'}
          ])
        });
        var work = new Ext.form.ComboBox({
          store: workDS,
          displayField:'name',
          hiddenName:'workId',
          valueField:'id',
          typeAhead: true,
          allowBlank:false,
          blankText:'请选择任务',
          minChars:0,
          anchor: '90%',
          mode: 'remote',
          fieldLabel:'任务',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择任务.....',
          selectOnFocus:true
        });

        var beginMinuteSpinner = new Ext.ux.form.SpinnerField({
          fieldLabel:'工作开始间隔分钟数',
          name:'begin_minute',
          minValue:0,
          anchor:'90%',
          value:0

        })

        var duringMinuteSpinner = new Ext.ux.form.SpinnerField({
          fieldLabel:'工作持续分钟数',
          name:'during_minute',
          minValue:0,
          anchor:'90%',
          value:0

        })

        var dynamic_during_minute = new Ext.ux.form.SpinnerField({
          fieldLabel:'动态工作持续分钟数',
          name:'dynamic_during_minute',
          minValue:0,
          anchor:'90%'
        })

        var description = new Ext.form.TextArea({
          fieldLabel:'描述',
          name:'description',
          anchor:'100%',
          height:80
        })
        var newStandardMaintenanceForm=new Ext.form.FormPanel({
          width:500,
          labelAlign: 'top',
          url:'/standardmaintenance/create?templateId='+templateId,
          buttonAlign:'center',
          autoHeight:true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          items:[{
              xtype:'hidden',
              name:'id',
              value:''
            },{
              layout:'column',
              items:[{
                  columnWidth:.5,
                  layout:'form',
                  items:[team]
                },{
                  columnWidth:.5,
                  layout:'form',
                  items:[work]
                }]
            },{
              layout:'column',
              items:[{
                  columnWidth:.5,
                  layout:'form',
                  items:[beginMinuteSpinner]
                },{
                  columnWidth:.5,
                  layout:'form',
                  items:[duringMinuteSpinner]
                }]
            },{
              layout:'column',
              items:[{
                  columnWidth:.5,
                  layout:'form',
                  items:[dynamic_during_minute]
                }]
            },{
              layout:'column',
              items:[{
                  columnWidth:1,
                  layout:'form',
                  items:[description]
                }]
            }],
          buttons:[{
              text:'确定',
              handler: function(){
                // check form value
                if (newStandardMaintenanceForm.form.isValid()) {
                  newStandardMaintenanceForm.form.submit({
                    method: 'post',
                    waitMsg: '正在创建维修任务...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        newStandardMaintenanceWin.destroy();
                      } else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                } else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                newStandardMaintenanceWin.destroy();
              }
            }]
        });
        newStandardMaintenanceForm.render('newStandardMaintenanceForm');
      })
    </script>
  </head>
  <body>
    <div id="newStandardMaintenanceForm"></div>
  </body>
</html>
